package cn.manyufun.myf.ui.news.presenter;


import cn.manyufun.myf.R;
import cn.manyufun.myf.bean.NewsSummaryList;
import cn.manyufun.myf.common.baserx.RxSubscriber;
import cn.manyufun.myf.ui.news.contract.NewsListContract;

/**
 * @author Kevin Xiao
 * @date Create Date: 2017-12-27
 * @Description
 */
public class NewsListPresenter extends NewsListContract.Presenter {

    @Override
    public void onStart() {
        super.onStart();
        //监听返回顶部动作
//        mRxManage.on(AppConstant.NEWS_LIST_TO_TOP, new Action1<Object>() {
//            @Override
//            public void call(Object o) {
//                mView.scrolltoTop();
//            }
//        });
    }

    /**
     * 请求获取列表数据
     *
     * @param type
     * @param id
     * @param startPage
     */
    @Override
    public void getNewsListDataRequest(String type, String id, int startPage) {
        mRxManage.add(mModel.getNewsListData(type, id, startPage)
                .subscribe(new RxSubscriber<NewsSummaryList>(mContext, false) {
                    @Override
                    public void onStart() {
                        super.onStart();
                        mView.showLoading(mContext.getString(R.string.loading));
                    }

                    @Override
                    protected void _onNext(NewsSummaryList newsSummaries) {
                        mView.returnNewsListData(newsSummaries);
                        mView.stopLoading();
                    }

                    @Override
                    protected void _onError(String message) {
                        mView.showErrorTip(message);
                    }
                }));
    }
}
